<template>
  <div class="comment-reply">
    <!-- 导航栏 -->
    <van-nav-bar :title="!comment.reply_count ? '暂无回复' :`${comment.reply_count}条回复`">
      <van-icon
        slot="left"
        name="cross"
        @click="$emit('close')"
      />
    </van-nav-bar>
    <!-- /导航栏 -->
    <ArticleComment
      :comment="comment"
      :isReply="true"
    />

    <van-cell title="所有回复" />

    <!-- 评论的回复列表 -->
    <ArticleList
      :list="list"
      @reply-click="$emit('reply-click', $event)"
      type="c"
      :source="comment.com_id"
    ></ArticleList>
    <!-- /评论的回复列表 -->

    <!-- 底部区域 -->
    <div class="reply-bottom">
      <van-button
        class="write-btn"
        size="small"
        round
        @click="isPostShow = true"
      >写评论</van-button>
    </div>
    <!-- /底部区域 -->

    <!-- 发布评论 -->
    <van-popup
      v-model="isPostShow"
      position="bottom"
    >
      <comment-post
        :target="comment.com_id"
        @post-success="onPostSuccess"
      />
    </van-popup>
    <!-- /发布评论 -->
  </div>
</template>

<script>
import ArticleList from '@/views/article/components/article-list'
import ArticleComment from '@/views/article/components/article-comment'
import CommentPost from '@/views/article/components/comment-post'
export default {
  name: 'CommentReply',
  components: {
    ArticleList,
    ArticleComment,
    CommentPost
  },
  props: {
    comment: {
      type: Object,
      required: true
    }
  },
  data () {
    return {
      loading: false,
      finished: false,
      list: [], // 评论回复列表
      offset: null, // 下一页评论
      isPostShow: false // 发布回复评论弹出层
    }
  },
  methods: {
    onPostSuccess (obj) {
      this.comment.reply_count++
      this.list.unshift(obj)
      // 关闭弹层
      this.isPostShow = false
    }
  }
}
</script>

<style lang="less" scoped>
.scroll-wrap {
  position: fixed;
  top: 92px;
  left: 0;
  right: 0;
  bottom: 88px;
  overflow-y: auto;
}

.reply-bottom {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #fff;
  border-top: 1px solid #d8d8d8;
  .write-btn {
    width: 60%;
  }
}
</style>
